package cn.pink.common;

import cn.pink.common.support.utils.TimeUtils;
import cn.pink.core.Port;
import cn.pink.core.Service;
import cn.pink.core.config.IronConfig;
import cn.pink.core.stat.StatRPC;
import cn.pink.core.support.TickTimer;

/**
 * 执行信息统计
 * @Author: pink
 * @Date: 2022/6/22 15:42
 */
public class StatService extends Service {
    /** 打印统计数据 */
    private TickTimer timer = new TickTimer(IronConfig.STAT_TIME * TimeUtils.SEC);

    public StatService(Port port) {
        super(port);
    }

    @Override
    public Object getId() {
        return "StatService";
    }

    @Override
    public void pulseOverride() {
        long now = port.getTimeCurrent();

        //打印统计信息
        if (timer.isPeriod(now)) {
            StatRPC.showResult();
        }
    }
}
